<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\business\EhrHelper;
use yii\helpers\ArrayHelper;

/* @var $this yii\web\View */
/* @var $searchModel common\models\qywx\QywxDepartmentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Qywx Departments');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="qywx-department-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Qywx Department'), ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a(Yii::t('app', 'Sync Department From HR'), ['sync-from-hr'], ['class' => 'btn btn-primary', 'target'=>'_blank']) ?>
    </p>
    <?php
    try {
        $gv = GridView::widget([
            'tableOptions' => ['class' => 'table table-condensed table-bordered table-striped table-hover'],
            'pager' => [
//            'class'          => GoPager::className(),
                'nextPageLabel'  => Yii::t('app', 'Next Page'),
                'prevPageLabel'  => Yii::t('app', 'Previous Page'),
                'firstPageLabel' => Yii::t('app', 'First Page'),
                'lastPageLabel'  => Yii::t('app', 'Last Page'),
                'options' => [
                    'class' => 'pagination pagination-sm m-t-none m-b-none',
                ],
            ],
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                [
                    'class'         => 'yii\grid\ActionColumn',
                    'template'      => '{sync-from-hr} {view} {update} {delete} {cascade-delete}',
                    'header'        => '操作',
                    'headerOptions' => ['class' => 'text-center no-margin'],
                    'buttons'       => [
                        'sync-from-hr' => function($url, $model, $key) {
                            $options = [
                                'title' => Yii::t('app', 'Sync Department From HR'),
                                'data-id' => $key,
                                'target' => '_blank',
                            ];
                            return Html::a('<span class="	glyphicon glyphicon-refresh edit-class"></span>', $url, $options);
                        },
                        'cascade-delete' => function($url, $model, $key) {
                            $options = [
                                'title' => Yii::t('app', 'Cascade Delete'),
                                'data-id' => $key,
                                'target' => '_blank',
                            ];
                            return Html::a('<span class="	glyphicon glyphicon-remove edit-class"></span>', $url, $options);
                        },
                    ],
                ],
                [
                    'class' => 'yii\grid\SerialColumn',
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
                ],

                [
                    'label' => Yii::t('app', 'Department Number'),
                    'attribute' => 'number',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
                [
                    'label' => Yii::t('app', 'Department Name'),
                    'attribute' => 'name',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
                [
                    'label' => Yii::t('app', 'Department Qywx ID'),
                    'attribute' => 'wx_id',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//            'qywx_department_parent_wx_id',
                [
                    'label' => Yii::t('app', 'Parent Department Qywx ID'),
                    'attribute' => 'parent_wx_id',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//            'qywx_department_order',
                [
                    'label' => Yii::t('app', 'Order'),
                    'attribute' => 'order',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//            'qywx_department_memo',
                [
                    'label' => Yii::t('app', 'Memo'),
                    'attribute' => 'memo',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//             'qywx_department_created_by',
                [
                    'label' => Yii::t('app', 'Created By'),
                    'attribute' => 'created_by',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//             'qywx_department_created_at',
                [
                    'label' => Yii::t('app', 'Created At'),
                    'attribute' => 'created_at',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//             'qywx_department_updated_by',
                [
                    'label' => Yii::t('app', 'Updated By'),
                    'attribute' => 'updated_by',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//             'qywx_department_updated_at',
                [
                    'label' => Yii::t('app', 'Updated At'),
                    'attribute' => 'updated_at',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
            ],
        ]);
    } catch (Exception $e) {
        $gv =  \common\business\CommonHelper::getExceptionMsg($e);
    }
    ?>
    <?= $gv ?>
</div>
